<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet" pageEncoding="UTF-8"%>
<%
String job_target = request.getParameter("job_target");
String university = request.getParameter("university");
String degree = request.getParameter("degree");
String pro_title = request.getParameter("pro_title");
String language = request.getParameter("language");
String proficiency = request.getParameter("proficiency");

String pageNum = request.getParameter("page");
pageNum = "".equals(pageNum) || pageNum == null ? "1" : pageNum;
int pageSize = 20;

String sqlwhere = " where 1=1 ";
if (!"".equals(job_target) && job_target != null) 
	sqlwhere = sqlwhere + " and stu.job_target like '%" + job_target + "%'";
if (!"".equals(university) && university != null) 
	sqlwhere = sqlwhere + " and edu.university like '%" + university + "%'";
if (!"".equals(degree) && degree != null) 
	sqlwhere = sqlwhere + " and edu.degree like '%" + degree + "%'";
if (!"".equals(pro_title) && pro_title != null) 
	sqlwhere = sqlwhere + " and pro.title like '%" + pro_title + "%'";
if (!"".equals(language) && language != null) 
	sqlwhere = sqlwhere + " and lan.language like '%" + language + "%'";
if (!"".equals(proficiency) && proficiency != null) 
	sqlwhere = sqlwhere + " and coms.proficiency like '%" + proficiency + "%'";
	
String sqlJoin = " left join dbf_education_background edu on edu.stuuser_id=stu.stuuser_id"
+" left join dbf_proqua pro on pro.stuuser_id=stu.stuuser_id"
+" left join dfb_languageskills lan on lan.stuuser_id=stu.stuuser_id"
+" left join dfb_computerskills coms on coms.stuuser_id=stu.stuuser_id";

String sqlCount = "select count(*) as cnt from dbf_stuuser stu" + sqlJoin + sqlwhere;

String sql="select stu.* from dbf_stuuser stu" + sqlJoin + sqlwhere;
sql = sql + " limit " + (Integer.valueOf(pageNum).intValue() - 1) * 20 + "," + pageSize;

System.out.println(sql);
Conn conn = new Conn();
ResultSet rs = conn.find(sqlCount);
rs.next();
int count = rs.getInt("cnt");
rs.close();
rs = conn.find(sql);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My applications</title>
	<link rel="stylesheet" type="text/css" href="../style.css">
  </head>
  
  <body>
  <table width="718" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="39" colspan="3" background="../images/main_title.jpg"><strong>&nbsp;&nbsp;&nbsp;&nbsp;<span class="menutitle">Job Seeker Search</span></strong></td>
    </tr>
    <tr>
      <td valign="bottom"><img src="../images/menu_a.jpg" width="19" height="23" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="bottom"><img src="../images/menu_b.jpg" width="18" height="23" /></td>
    </tr>
    <tr>
      <td width="19" valign="top" background="../images/menu_c.jpg"><img src="../images/menu_c.jpg" width="19" height="54" /></td>
      <td width="681" valign="top"><form action="searchResumes.jsp" method="post">
  	<table border="0" cellpadding="0" cellspacing="0" class="logintxt" style="width:100%">
    	<tr>
    		<td colspan="2">
			Job Target:  			</td>
  			<td width="18%">
  				<input name="job_target" type="text" class="logintxt" id="job_target" size="15">  			</td>
  			<td width="9%">
  				University:  			</td>
  			<td width="19%">
  				<input name="university" type="text" class="logintxt" id="university" size="15">  			</td>
  			<td width="10%">
  				Degree:  			</td>
  			<td colspan="2">
  				<input name="degree" type="text" class="logintxt" id="degree" size="15">  			</td>
		  </tr>
  		<tr>
  			<td colspan="2">
			Professional Qualification: </td>
  			<td>
  				<input name="pro_title" type="text" class="logintxt" id="pro_title" size="15">  			</td>
  			<td>
  				Language:  			</td>
  			<td>
  				<input name="language" type="text" class="logintxt" id="language" size="15">  			</td>
  			<td>
  				Proficiency:  			</td>
  			<td colspan="2">
  				<input name="proficiency" type="text" class="logintxt" id="proficiency" size="15">  			</td>
		  </tr>
  		<tr>
  		  <td></td>
  		  <td colspan="6" align="center">&nbsp;</td>
  		  <td></td>
		  </tr>
  		<tr>
  			<td width="14%"></td>
  			<td colspan="6" align="center">
  				<input type="image" src="../images/search_btn.jpg" value="search">  			</td>
  			<td width="12%"></td>
  		</tr>
    </table>
    <br>
  	<table border="0" cellspacing="0" cellpadding="0" style="width:100%">
  		<tr>
  			<td><table border="1" cellpadding="0" cellspacing="0" class="logintxt" style="width:100%">
              <tr>
                <td colspan="5" style="text-align:right"><%="1".equals(pageNum) ? "First" : "<a href=\"searchResumes.jsp?page=1" 
  							+ "&job_target=" + request.getParameter("job_target") == null ? "": request.getParameter("job_target")
  							+ "&university=" + request.getParameter("university") == null ? "": request.getParameter("university")
  							+ "&degree=" + request.getParameter("degree") == null ? "": request.getParameter("degree")
  							+ "&pro_title=" + request.getParameter("pro_title") == null ? "": request.getParameter("pro_title")
  							+ "&language=" + request.getParameter("language") == null ? "": request.getParameter("language")
  							+ "&proficiency=" + request.getParameter("proficiency") == null ? "": request.getParameter("proficiency")
  							+ "\">First</a>" %>&nbsp;&nbsp; <%="1".equals(pageNum) ? "Previous" : "<a href=\"searchResumes.jsp?page=" 
  							+ String.valueOf(Integer.valueOf(pageNum).intValue() - 1) 
  							+ "&job_target=" + request.getParameter("job_target") == null ? "": request.getParameter("job_target")
  							+ "&university=" + request.getParameter("university") == null ? "": request.getParameter("university")
  							+ "&degree=" + request.getParameter("degree") == null ? "": request.getParameter("degree")
  							+ "&pro_title=" + request.getParameter("pro_title") == null ? "": request.getParameter("pro_title")
  							+ "&language=" + request.getParameter("language") == null ? "": request.getParameter("language")
  							+ "&proficiency=" + request.getParameter("proficiency") == null ? "": request.getParameter("proficiency")
  							+ "\">Previous</a>" %>&nbsp;&nbsp; <%=((Integer.valueOf(pageNum).intValue() * pageSize)) < count ? "<a href=\"searchResumes.jsp?page=" 
  							+ String.valueOf(Integer.valueOf(pageNum).intValue() + 1) 
  							+ "&job_target=" + request.getParameter("job_target") == null ? "": request.getParameter("job_target")
  							+ "&university=" + request.getParameter("university") == null ? "": request.getParameter("university")
  							+ "&degree=" + request.getParameter("degree") == null ? "": request.getParameter("degree")
  							+ "&pro_title=" + request.getParameter("pro_title") == null ? "": request.getParameter("pro_title")
  							+ "&language=" + request.getParameter("language") == null ? "": request.getParameter("language")
  							+ "&proficiency=" + request.getParameter("proficiency") == null ? "": request.getParameter("proficiency") 
  							+ "\">Next</a>" : "Next" %>&nbsp;&nbsp; <%=((Integer.valueOf(pageNum).intValue() * pageSize)) >= count ? "Last" : "<a href=\"searchResumes.jsp?page=" 
  							+ (count % pageSize == 0 ? count / pageSize : count / pageSize + 1) 
  							+ "&job_target=" + request.getParameter("job_target") == null ? "": request.getParameter("job_target")
  							+ "&university=" + request.getParameter("university") == null ? "": request.getParameter("university")
  							+ "&degree=" + request.getParameter("degree") == null ? "": request.getParameter("degree")
  							+ "&pro_title=" + request.getParameter("pro_title") == null ? "": request.getParameter("pro_title")
  							+ "&language=" + request.getParameter("language") == null ? "": request.getParameter("language")
  							+ "&proficiency=" + request.getParameter("proficiency") == null ? "": request.getParameter("proficiency")
  							+ "\">Last</a>" %> </td>
              </tr>
              <tr>
                <td colspan="5" height="5"></td>
              </tr>
              <tr>
                <th width="22%" class="style4" style="background-color:#FFC963">Name</th>
                <th width="9%" class="style4" style="background-color:#FFC963">Sex</th>
                <th width="36%" nowrap class="style4" style="background-color:#FFC963">Email address</th>
                <th width="21%" class="style4" style="background-color:#FFC963">Contact Phone</th>
                <th width="12%" class="style4" style="background-color:#FFC963">Resume</th>
              </tr>
              <%
  						while(rs.next()) {
  					%>
              <tr>
                <td class="logintxt"><%=rs.getString("name") %></td>
                <td class="logintxt"><%=rs.getString("sex") %></td>
                <td class="logintxt"><%=rs.getString("email") %></td>
                <td class="logintxt"><%=rs.getString("Contact_Phone") %></td>
                <td class="logintxt"><a href="stuResume.jsp?stuuser_id=<%=rs.getString("stuuser_id")%>">view</a></td>
              </tr>
              <%} %>
              <tr>
                <td colspan="5" height="20">&nbsp;</td>
              </tr>
            </table></td>
		  </tr>
    </table>
  </form></td>
      <td width="18" valign="top" background="../images/menu_d.jpg"><img src="../images/menu_d.jpg" width="18" height="54" /></td>
    </tr>
    <tr>
      <td><img src="../images/menu_e.jpg" width="19" height="25" /></td>
      <td background="../images/menu_f.jpg"><img src="../images/menu_f.jpg" width="181" height="25" /></td>
      <td><img src="../images/menu_g.jpg" width="18" height="25" /></td>
    </tr>
  </table>
  
  </body>
</html>
